<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top:50px"
    cancelText="关闭">
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="开始日期">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.startTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.startTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
<!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
<!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
<!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">


      </a-table>
    </div>

<!--    <buss-material-procurement-plan-modal ref="modalForm" :applications="applications" @ok="modalFormOk"/>-->

<!--    <applications-list-modal ref="selectApplicationList"-->
<!--                          @applicationsOk="applicationsOk">-->
<!--    </applications-list-modal>-->
  </a-card>
  </j-modal>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  // import BussMaterialProcurementPlanModal from './modules/BussMaterialProcurementPlanModal'
  import '@/assets/less/TableExpand.less'
  // import ApplicationsListModal from "@comp/base/modal/ApplicationsListModal";

  export default {
    name: "BussMaterialProcurementPlanList",
    mixins:[JeecgListMixin],
    components: {
      // ApplicationsListModal
    },
    props:{
      modalWidth: {
        type: Number,
        required: false,
        default: 1250
      },
      checkval: {
        type: String,
        default: 'radio'
      },
      title:{
        type: String,
        default: ""
      }
    },
    data () {
      return {
        description: '原料采购计划单管理页面',
        applications: {},
        visible: false,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单据编号',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'原料编号',
            align:"center",
            dataIndex: 'materialCode'
          },
          {
            title:'原料名称',
            align:"center",
            dataIndex: 'materialName'
          },
          {
            title:'规格',
            align:"center",
            dataIndex: 'spec'
          },
          {
            title:'数量',
            align:"center",
            dataIndex: 'num'
          },
          {
            title:'制单日期',
            align:"center",
            dataIndex: 'createTime',
            // customRender:function (text) {
            //   return !text?"":(text.length>10?text.substr(0,10):text)
            // }
          },
          {
            title:'开始日期',
            align:"center",
            dataIndex: 'startTime',
            // customRender:function (text) {
            //   return !text?"":(text.length>10?text.substr(0,10):text)
            // }
          },
          {
            title:'结束日期',
            align:"center",
            dataIndex: 'endTime',
            // customRender:function (text) {
            //   return !text?"":(text.length>10?text.substr(0,10):text)
            // }
          },
          {
            title:'提报日期',
            align:"center",
            dataIndex: 'submissionDate',
            // customRender:function (text) {
            //   return !text?"":(text.length>10?text.substr(0,10):text)
            // }
          },
          {
            title:'用途',
            align:"center",
            dataIndex: 'useDesc'
          },
          {
            title:'是否开启',
            align:"center",
            dataIndex: 'status'
          },
          {
            title:'到货日期',
            align:"center",
            dataIndex: 'arrivalDate'
          },
        ],
        url: {
          list: "/plan/bussMaterialProcurementPlan/list",
          delete: "/plan/bussMaterialProcurementPlan/delete",
          deleteBatch: "/plan/bussMaterialProcurementPlan/deleteBatch",
          exportXlsUrl: "/plan/bussMaterialProcurementPlan/exportXls",
          importExcelUrl: "plan/bussMaterialProcurementPlan/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      close() {
        this.searchReset(false);
        this.visible = false;
      },
      handleSubmit() {
        this.getGoodsSelectRows();
        this.searchReset(false)
        this.onClearSelected();
        this.close();
      },
      getGoodsSelectRows() {
        let selectedRow = null;
        if(this.checkval=='radio'){
          selectedRow = this.selectionRows[0];
        }else{
          selectedRow = this.selectedRowKeys
        }
        // let selectedRow = this.selectionRows[0];
        //传递选中的数据
        this.$emit("ok", selectedRow);
      },
      add(){
        this.visible = true;
        this.loadData();
      },
      applicationsOk(row) {
        this.applications = row;
        console.log("applications" , this.applications);
        this.handleAdd();
      },
      handleAddApplications() {
        this.$refs.selectApplicationList.add();
        this.$refs.selectApplicationList.title = "选择请购单";
        this.$refs.selectApplicationList.disableSubmit = false;
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'code',text:'单据编号',dictCode:''})
        fieldList.push({type:'string',value:'applicationId',text:'请购单ID',dictCode:''})
        fieldList.push({type:'date',value:'startTime',text:'开始日期'})
        fieldList.push({type:'date',value:'endTime',text:'结束日期'})
        fieldList.push({type:'date',value:'submissionDate',text:'提报日期'})
        fieldList.push({type:'string',value:'status',text:'是否开启',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>